package org.openit.portail.dao.impl;

import java.util.List;

import org.hibernate.SessionFactory;
import org.openit.portail.dao.ModeleDao;
import org.openit.portail.model.ModelePaiement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;


@Repository
@Transactional
public class ModeleDaoImpl implements ModeleDao {

	private SessionFactory sessionFactory;

	public ModelePaiement get(Long id) {
		return (ModelePaiement) sessionFactory.getCurrentSession()
			.createQuery("from ModelePaiement modele where modele.id = :id")
			.setLong("id", id).uniqueResult();
	}

	public void delete(ModelePaiement modele) {
		sessionFactory.getCurrentSession().delete(modele);
	}

	@SuppressWarnings("unchecked")
	public List<ModelePaiement> findAll() {
		return sessionFactory.getCurrentSession().createQuery("from ModelePaiement").list();
	}

	public void save(ModelePaiement modele) {
		sessionFactory.getCurrentSession().merge(modele);
		
	}
	
	@Autowired
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	@SuppressWarnings("unchecked")
	public List<ModelePaiement> findVyService(Long id) {
		@SuppressWarnings("rawtypes")
		List list = sessionFactory.getCurrentSession()
		.createQuery("from ModelePaiement modele where modele.idService = :id")
		.setLong("id", id).list();
		return list;
	}

	
}
